package eud.zbjs.dragonet.android_;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Shader;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main_1), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        }); //全屏模式增加适应能力

        findViewById(R.id.bt_1).setOnClickListener(this);
        TextView myTextView = findViewById(R.id.textView);

// 设置渐变的起始和结束颜色
        int startColor = Color.parseColor("#FF1493");
        int endColor = Color.parseColor("#FF69B4");

// 创建线性渐变
        float centerX = myTextView.getPaint().measureText(myTextView.getText().toString()) / 2;
        LinearGradient shader = new LinearGradient(
                0, 0, centerX, myTextView.getTextSize(), // 渐变从左到右
                startColor, endColor,
                Shader.TileMode.CLAMP); // 渐变边缘处理方式

// 设置渐变到TextView的画笔
        myTextView.getPaint().setShader(shader);
// 重新绘制TextView
        myTextView.invalidate();
        Button bt_2 = findViewById(R.id.bt_2);
        bt_2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this, "尽情期待", Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(this, MainActivity2.class);
        startActivity(intent);
    }
}